//
//  BETechsListController.swift
//  BEGlobalOiler
//
//  Created by KKING on 16/9/20.
//  Copyright © 2016年 Bullseye Energy pte ltd. All rights reserved.
//

import UIKit

class BETechsListController: UITableViewController {
    
    var techListViewModel: BETechListViewModel = BETechListViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        loadData()
        setupTableView()
    }
    
    private func setupTableView(){
        tableView.register(UINib(nibName: "BETechListCell", bundle: nil), forCellReuseIdentifier: "techListCell")
        tableView.rowHeight = 150
    }
    
    
    private func loadData(){
        JFProgressHUD.showloading()
        showNetworkActivity()
        techListViewModel.loadTechListData{ (success, tip) in
            JFProgressHUD.dismiss()
            if success {
                JFProgressHUD.showSuccessWithStatus(status: "")
                DispatchQueue.main.async(execute: {
                    self.tableView.reloadData()
                })
            } else {
                JFProgressHUD.showInfoWithStatus(status: tip)
            }
        }
    }
    
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return techListViewModel.techVModelDatas.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "techListCell", for: indexPath) as! BETechListCell
        cell.techViewModel = techListViewModel.techVModelDatas[indexPath.row]
        return cell
    }
}

